//------------------------------------------------------------------------------
// Copyright (c) 2012 by Silicon Laboratories.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Silicon Laboratories End User
// License Agreement which accompanies this distribution, and is available at
// http://developer.silabs.com/legal/version/v10/License_Agreement_v10.htm
// Original content and implementation provided by Silicon Laboratories.
//------------------------------------------------------------------------------

//==============================================================================
// WARNING:
//
// This file is auto-generated by AppBuilder and should not be modified.
// Any hand modifications will be lost if the project is regenerated.
//==============================================================================
// library
#include <stdio.h>
// hal
#include <si32_device.h>
#include <SI32_CLKCTRL_A_Type.h>
#include <SI32_UART_B_Type.h>
#include <SI32_PBSTD_A_Type.h>
// application
#include "myUart0.h"

//==============================================================================
//MODE FUNCTIONS
//==============================================================================
//------------------------------------------------------------------------------
// myUART0_run_async_uart_mode()
//
// This function prints a menu to the UART terminal and waits for the user
// to press a key.
//------------------------------------------------------------------------------
void myUART0_run_async_uart_mode(void)
{
   unsigned int inputcharacter;       // Used to store character from UART
   printf ("   Enter character:\n\r");
   inputcharacter = myUART0_get_char();
   printf ("Character entered : %c\n\r", inputcharacter);
   printf ("      Value in Hex: 0x%2X\n\n\r",  inputcharacter);
}

//==============================================================================
//SUPPORT FUNCTIONS
//==============================================================================

//------------------------------------------------------------------------------
// myUART0_send_char()
//
// Outputs a single character to UART0.  This function is called by
// a modified version of fputc() defined in "retarget_arm.c".
//------------------------------------------------------------------------------
void myUART0_send_char(uint8_t val)
{
  // Block if the output buffer is full
  while (SI32_UART_B_read_tx_fifo_count(SI32_UART_0) >= 4);

  // Write character to the output buffer
  SI32_UART_B_write_data_u8(SI32_UART_0, val);
}

//------------------------------------------------------------------------------
// myUART0_get_char()
//
// Returns a single character received from UART0.  This function is called by
// a modified version of fgetc() defined in "retarget_arm.c".
//
// Note: This is a blocking function.
//------------------------------------------------------------------------------
uint8_t myUART0_get_char(void)
{

  uint8_t val;

  // Block if input buffer is empty
  while (SI32_UART_B_read_rx_fifo_count(SI32_UART_0) == 0);

  // Read character from the input buffer
  val = SI32_UART_B_read_data_u8(SI32_UART_0);

  return val;
}


//-eof--------------------------------------------------------------------------
